"use client";

import { Result } from "antd";
import { type ReactNode } from "react";
import { ErrorBoundary as ReactErrorBoundary } from "react-error-boundary";

interface ErrorBoundaryProps {
  children: ReactNode;
}

function ErrorFallback({ error }: { error: Error }) {
  return (
    <Result
      status="error"
      title="出错了"
      subTitle={error.message || "加载失败，请重试"}
    />
  );
}

export function ErrorBoundary({ children }: ErrorBoundaryProps) {
  return (
    <ReactErrorBoundary FallbackComponent={ErrorFallback}>
      {children}
    </ReactErrorBoundary>
  );
} 